var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ifShownoData: true,
    bankcardInfoVo:"",
    name: "",
    bankCard:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    //that.onMineInfo();
  },
  onMineInfo: function() {
    var that = this;
    wx.request({
      method: "POST",
      url: 'https://www.zaishengwang.com/wx/toHomeUser.do',
      dataType: 'json',
      header: {
        'content-type': 'application/x-www-form-urlencoded',
      },
      data: {
        id: app.globalData.userId,
      },
      success: function(res) {
       // console.log(res.data);
        //console.log(res.data.bankcardInfoVo);
        that.setData({
          userVo: res.data.userVo
        });
        if (res.data.bankcardInfoVo == "1"){
          that.setData({ ifShownoData: false});
        }else{
          var name = "*" + res.data.bankcardInfoVo.bankName.substr(1);
          var bankCard = "************" + res.data.bankcardInfoVo.bankCardNumber.substr(-4);
          that.setData({ name: name, bankCard: bankCard, bankcardInfoVo: res.data.bankcardInfoVo,ifShownoData: true });
        }
      },
      fail: function(error) {
        console.log(error);
      }
    })
  },
  goBindBandCard: function() {
    var that = this;
    var auditStatus = that.data.userVo.auditStatus;
    if (auditStatus != 3) {
      // wx.showModal({
      //   title: '身份认证成功才能设置支付密码',
      //   confirmColor: '#56BDE0',
      //   showCancel: false,
      //   success: function (res) {
      //     wx.navigateTo({
      //       url: 'authentication'
      //     })
      //   }
      // });

      wx.showModal({
        title: '提示',
        content: '身份认证成功才能设置支付密码',
        confirmText: "去认证",
        confirmColor: "#56BDE0",
        success(res) {
          if (res.confirm) {
            // console.log('用户点击确定');
            wx.navigateTo({
              url: 'authentication'
            })
          } else if (res.cancel) {
            //console.log('用户点击取消')
          }
        }
      });
      
    } else {
      var cardName = that.data.userVo.cardName;
      var cardNum = that.data.userVo.cardNum;
      var payStatus = that.data.userVo.payStatus;
      wx.navigateTo({
        url: 'bindBandCard?cardName=' + cardName + '&cardNum=' + cardNum + '&payStatus=' + payStatus,
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this;
    that.onMineInfo();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})